<link rel="stylesheet" href="/back/css/file_uploader/bootstrap.min.css">
<link rel="stylesheet" href="/back/css/file_uploader/bootstrap-image-gallery.min.css">
<link rel="stylesheet" href="/back/css/file_uploader/jquery.fileupload-ui.css">

<script>
    $(document).ready(function() {
        var getExistsFolders = function() {
            $.post('/admin/ajax/image-folders', {}, function(response) {                                    
                response = JSON.parse(response);
                for (var i in response) {
                    $('select[name="image_folders_multiupload"]').append('<option>' + response[i] + '</option>');
                }
            })
        }
        $('input[name="create_folder_btn_multiupload"]').live('click', function() {
            createFolder();
        });
        var createFolder = function() {            
            var data = {
                folder_name: $('input[name="new_folder_multiupload"]').val()
            };
            $.post('/admin/ajax/create-folder', data, function(response) {
                response = JSON.parse(response);
                if (response.result == 'success') {                    
                    $('select[name="image_folders_multiupload"]').append('<option>' + response.folder_name + '</option>');
                }
                $('#create_folder_result_multiupload').html(response.message);
                $('#create_folder_result_multiupload').show();
            })
        }
        getExistsFolders();
    })
</script>

<!--<a href="#myModal" role="button" data-toggle="modal">Launch demo modal</a>-->
 
<div id="myModal" class="modal hide fade" style="width: 750px;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Мультизагрузка изображений</h3>
    </div>
    <div class="modal-body">
        <form id="fileupload" action="/admin/ajax/image-upload" method="POST" enctype="multipart/form-data">
        <div class="row fileupload-buttonbar">
            <div class="span9">                
                <!--<span class="btn btn-success fileinput-button">
                    <i class="icon-plus icon-white"></i>
                    <span>Выбор файлов</span>
                    <input type="file" name="files[]" multiple>
                </span>-->
                Выберите папку: <br />
                <select name="image_folders_multiupload">                    
                </select>
                <br />
                Или создайте новую:<input type="text" value="" name="new_folder_multiupload"/>
                                   <input type="button" name="create_folder_btn_multiupload" value="создать" />
                <br />
                <p id="create_folder_result_multiupload" style="display: none;"></p>
                <span class="field">
                    <input type="file" name="files[]" multiple />
                </span>
                <button type="submit" class="btn btn-primary start">
                    <i class="icon-upload icon-white"></i>
                    <span>Загрузить все</span>
                </button>
                <button type="reset" class="btn btn-warning cancel">
                    <i class="icon-ban-circle icon-white"></i>
                    <span>Отменить все</span>
                </button>
                <button type="button" class="btn btn-danger delete">
                    <i class="icon-trash icon-white"></i>
                    <span>Удалить все</span>
                </button>
                <input type="checkbox" class="toggle">
                <input type="hidden" name="folder_name_multiupload" value=""/>                
                <span class="fileupload-loading"></span>
            </div>
            <div class="span5 fileupload-progress fade">
                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                    <div class="bar" style="width:0%;"></div>
                </div>
                <div class="progress-extended">&nbsp;</div>
            </div>
        </div>
        <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
        </form>

        <script id="template-upload" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
        <tr class="template-upload fade">
            <td>
                <span class="preview"></span>
            </td>
            <td>
                <p class="name">{%=file.name%}</p>
                {% if (file.error) { %}
                    <div><span class="label label-important">Error</span> {%=file.error%}</div>
                {% } %}
            </td>
            <td>
                <p class="size">{%=o.formatFileSize(file.size)%}</p>
                {% if (!o.files.error) { %}
                    <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
                {% } %}
            </td>
            <td>
                {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                    <button class="btn btn-primary start">
                        <i class="icon-upload icon-white"></i>
                        <span>Start</span>
                    </button>
                {% } %}
                {% if (!i) { %}
                    <button class="btn btn-warning cancel">
                        <i class="icon-ban-circle icon-white"></i>
                        <span>Cancel</span>
                    </button>
                {% } %}
            </td>
        </tr>
        {% } %}
        </script>
        <!-- The template to display files available for download -->
        <script id="template-download" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
        <tr class="template-download fade">
            <td>
                <span class="preview">
                    {% if (file.thumbnail_url) { %}
                        <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
                    {% } %}
                </span>
            </td>
            <td>
                <p class="name">
                    <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
                </p>
                {% if (file.error) { %}
                    <div><span class="label label-important">Error</span> {%=file.error%}</div>
                {% } %}
            </td>
            <td>
                <span class="size">{%=o.formatFileSize(file.size)%}</span>
            </td>
            <td>
                <button class="btn btn-danger delete" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                    <i class="icon-trash icon-white"></i>
                    <span>Delete</span>
                </button>
                <input type="checkbox" name="delete" value="1" class="toggle">
            </td>
        </tr>
        {% } %}
        </script>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>      
    </div>
</div>


<script src="/back/js/file_uploader/vendor/jquery.ui.widget.js"></script>
<script src="/back/js/file_uploader/tmpl.min.js"></script>
<script src="/back/js/file_uploader/load-image.min.js"></script>
<script src="/back/js/file_uploader/canvas-to-blob.min.js"></script>
<script src="/back/js/file_uploader/bootstrap.min.js"></script>
<script src="/back/js/file_uploader/bootstrap-image-gallery.min.js"></script>
<script src="/back/js/file_uploader/jquery.iframe-transport.js"></script>
<script src="/back/js/file_uploader/jquery.fileupload.js"></script>
<script src="/back/js/file_uploader/jquery.fileupload-process.js"></script>
<script src="/back/js/file_uploader/jquery.fileupload-resize.js"></script>
<script src="/back/js/file_uploader/jquery.fileupload-validate.js"></script>
<script src="/back/js/file_uploader/jquery.fileupload-ui.js"></script>
<script src="/back/js/file_uploader/main.js"></script>